<?php
include('../class/abstract/class_paginator.php');
if($_GET['id'] && $_GET['city'] && $_GET['tabId'])
{
	include('../../class/class_connect.php');
	$aConnect=new connect('f');
	$row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
	if($_GET['tabId']=='5')
	{
    	include('../class/class_comments.php');
		$comments=new comments('firms', $_GET['city'], $_GET['id']);
		if(!$_GET['pageNum'])
		{
			$aConnect=new connect('fc');
			$num=mysql_num_rows($aConnect->select_all($_GET['city'], "WHERE f_id='".$_GET['id']."'"));
			echo ('<input name="comNum" id="comNum" type="hidden" value="'.$num.'">');
			$comments->commentForm();
		}
		$comments->showComments(10, $_GET['pageNum']);
	}
	if($_GET['tabId']=='1')
	{
		echo ('
		<link rel="stylesheet" type="text/css" href="style/aboutFirms.css" />
        <script type="text/javascript" src="scripts/showPhoto.js">
        </script>
		<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			for($i=1; $i<=2; $i++)
			{
				$Headers = @get_headers('http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg');
				if(preg_match("|200|", $Headers[0]))
				{
					echo ('
					<td class="aPhotoTd" align="center">
						<div class="aPhoto">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg">
						</div>
					</td>
					');
				}
			}
			echo ('
				</tr>
			</table>
			<table>
				<tr>
			');
			for($i=3; $i<=4; $i++)
			{
				$Headers = @get_headers('http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg');
				if(preg_match("|200|", $Headers[0]))
				{
					echo ('
					<td class="aPhotoTd" align="center">
						<div class="aPhoto">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg">
						</div>
					</td>
					');
				}
			}
			echo ('
			</tr>
			</table>
		</div>
		');
		$text=nl2br($row['stext']);
    	echo ('
    	<div class="about">
    		<div class="textTitle">
    			'.$row['text_title'].'
    		</div>
    		<div class="text">
    			'.$text.'
    		</div>
    	</div>
    	<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			for($i=5; $i<=6; $i++)
			{
				$Headers = @get_headers('http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg');
				if(preg_match("|200|", $Headers[0]))
				{
					echo ('
					<td class="aPhotoTd" align="center">
						<div class="aPhoto">
						'.$headers[0].'
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg">
						</div>
					</td>
					');
				}
			}
			echo ('
				</tr>
			</table>
			<table>
				<tr>
			');
			for($i=7; $i<=8; $i++)
			{
				$Headers = @get_headers('http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg');
				if(preg_match("|200|", $Headers[0]))
				{
					echo ('
					<td class="aPhotoTd" align="center">
						<div class="aPhoto">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg">
						</div>
					</td>
					');
				}
			}
			echo ('
				</tr>
			</table>
			<table>
				<tr>
			');
			for($i=9; $i<=10; $i++)
			{
				$Headers = @get_headers('http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg');
				if(preg_match("|200|", $Headers[0]))
				{
					echo ('
					<td class="aPhotoTd" align="center">
						<div class="aPhoto">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="http://pro-gorod.com/pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg">
						</div>
					</td>
					');
				}
			}
			echo ('
				</tr>
			</table>
		</div>
		');
	}
	if($_GET['tabId']=='2')
	{
		include('../class/class_news.php');
		$aNews=new news('firms', $_GET['city'], $_GET['id']);
		$newsConnect=new connect('fn');
		$newsesNum=mysql_num_rows($aConnect->select_all($_GET['city'], "WHERE firms_id='".$_GET['id']."'"));
		if(!$_GET['pageNum'])
		{
			echo ('<input name="newsNum" id="newsNum" type="hidden" value="'.$newsesNum.'">');
		}
		$aNews->showNews('fullnews.php?city='.$_GET['city'].'&obj=firms&id='.$_GET['id'].'&news_id=', 10, $_GET['pageNum']);
	}
	if($_GET['tabId']=='3')
	{
		include('../class/class_acts.php');
		$act=new acts();
		$act->showActs('firms', 100, 1000, $_GET['id']);
	}
	if($_GET['tabId']=='4')
	{
		$aConnect=new connect('p');
		$prices=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE firms_id='".$_GET['id']."'"));
		include('../../class/class_prices.php');
		class showPrice extends prices
		{
			function showPrices($tables, $a, $b, $limit){
				parent::showTables($tables, $a, $b, $limit);
			}
			function showTd($tdClass, $tdId, $tdValue, $temp='')
			{
				if($tdClass=='img')
				{
					$Headers = @get_headers('http://pro-gorod.com/pictures/pricepics/'.$_GET['city'].'/'.$_GET['id'].'/'.$tdId.'.jpg');
					if(preg_match("|200|", $Headers[0]))
						echo '<img src="http://pro-gorod.com/pictures/pricepics/'.$_GET['city'].'/'.$_GET['id'].'/'.$tdId.'.jpg?'.rand().'" />';
				}
				elseif($tdClass=='name' || $tdClass=='brend' || $tdClass=='model')
					echo '<a href="products.php?city='.$_GET['city'].'&product='.$tdValue.'">'.$tdValue.'</a>';
				else
					echo $tdValue;
			}
			function showHeader($table, $header=array())
			{
				$headerEmty=true;
				foreach($header as $key=>$vol)
				{
					if($vol && $vol!='')$headerEmty=false;
				}
				if($header && !$headerEmpty)
				{
					echo ('
					<tr id="headerTr'.$table.'" class="headerTr">
					');
					for($i=1; $i<=count($header); $i++)
					{
						echo ('
						<td id="headerTd'.$table.$i.'" class="headerTd">
							'.$header[$i-1].'
						</td>
						');
					}
					echo ('
					</tr>
					');
				}
			}
			function showTabName($tabName, $table)
			{
				echo ('
				<h3>'.$tabName.'</h3>
				');
			}
			function showColType($table, $colType){}
		}

		$tabs=explode('`', $prices['stext']);
		for($i=1; $i<=count($tabs); $i++)
		{
			$tabEls=explode('~', $tabs[$i-1]);
			$tabNames[$i]=$tabEls[0];
		}
		echo ('
			<div class="priceTabs">
			');
			foreach($tabNames as $page=>$name)
			{
				$class="priceTab";
				if($page==$_GET['priceTab'])$class="priceTabChosen";
				if(!$_GET['priceTab'] && $page=="1")$class="priceTabChosen";
				echo ('
				<div class="'.$class.'">
					<div class="priceTabBut" id="'.$page.'">'.$name.'</div>
				</div>
				');
			}
			echo ('
			</div>
		');
		echo ('
		<link rel="stylesheet" type="text/css" href="style/price.css" />
		<div class="prices">
			<div class="showPrices">
		');
			if(!$_GET['priceTab'])$limit=array(1,1);
			else $limit=array(1,$_GET['priceTab']);
			$aShowPrice=new showPrice($prices['stext']);
		    $aShowPrice->showPrices($prices['stext'], false, false, $limit);
		echo ('
			</div>
		</div>
		');
	}
}
else exit();
?>